package remoting

import (
	"context"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
)

func GetPodLogs(ctx context.Context, namespace string, name string, opts *corev1.PodLogOptions) ([]byte, error) {
	// 创建 Kubernetes API 客户端
	client, err := kubernetes.NewForConfig(restConfig)
	if err != nil {
		return nil, err
	}
	// 获取 Pod 的日志
	raw, err := client.CoreV1().Pods(namespace).GetLogs(name, opts).MaxRetries(3).DoRaw(ctx)
	if err != nil {
		return nil, err
	}
	return raw, nil
}

func TailLinesLogOptions(container string, tailLines int64) *corev1.PodLogOptions {
	return &corev1.PodLogOptions{
		Container: container,
		TailLines: &tailLines,
	}
}

func SinceSecondsLogOptions(container string, sinceSeconds int64, limitByte int64) *corev1.PodLogOptions {
	return &corev1.PodLogOptions{
		Container:    container,
		SinceSeconds: &sinceSeconds,
		LimitBytes:   &limitByte,
	}
}

func SinceTimeLogOptions(container string, sinceTime *metav1.Time, limitByte int64) *corev1.PodLogOptions {
	return &corev1.PodLogOptions{
		Container:  container,
		SinceTime:  sinceTime,
		LimitBytes: &limitByte,
	}
}
